<%= render partial: 'spree/admin/shared/order_tabs', locals: { current: :state_changes } %>

<% content_for :page_title do %>
  <%= plural_resource_name(Spree::StateChange) %>
<% end %>

<% if @state_changes.any? %>
  <table class="table" id="listing_order_state_changes" data-hook>
    <thead>
      <tr data-hook="admin_orders_state_changes_headers">
        <th><%= Spree::StateChange.human_attribute_name(:type) %></th>
        <th><%= Spree::StateChange.human_attribute_name(:state_from) %></th>
        <th><%= Spree::StateChange.human_attribute_name(:state_to) %></th>
        <th><%= Spree::StateChange.human_attribute_name(:user) %></th>
        <th><%= Spree::StateChange.human_attribute_name(:timestamp) %></th>
      </tr>
    </thead>

    <tbody>
      <% @state_changes.each do |state_change| %>
        <tr>
          <td><%= Spree.t("state_machine_states.#{state_change.name}") %></td>
          <td><%= state_change.previous_state ? Spree.t(state_change.previous_state) : Spree.t(:previous_state_missing) %></td>
          <td><%= Spree.t(state_change.next_state) %></td>
          <td>
            <%= link_to state_change.user.login, spree.admin_user_path(state_change.user) if state_change.user %>
          </td>
          <td>
            <%= pretty_time(state_change.created_at) %>
            <% if state_change.created_at != state_change.updated_at %>
              <small><%= Spree::StateChange.human_attribute_name(:updated) %>: <%= pretty_time(state_change.updated_at) %></small>
            <% end %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% else %>
  <div class="alert alert-info no-objects-found">
    <%= Spree.t(:no_state_changes) %>
  </div>
<% end %>
